package com.springboot.thread.asynctool;

import com.alibaba.fastjson.JSON;
import com.tlcsdm.async.callback.ICallback;
import com.tlcsdm.async.callback.IWorker;
import com.tlcsdm.async.executor.timer.SystemClock;
import com.tlcsdm.async.worker.WorkResult;
import com.tlcsdm.async.wrapper.WorkerWrapper;

import java.util.Map;

public class WorkerA implements IWorker<Integer, Integer>, ICallback<Integer, Integer> {

    @Override
    public void begin() {
        System.out.println("A - Thread:" + Thread.currentThread().getName() + "- start --" + SystemClock.now());
    }

    @Override
    public void result(boolean b, Integer integer, WorkResult<Integer> workResult) {
        System.out.println("A - param:" + JSON.toJSONString(integer));
        System.out.println("A - result:" + JSON.toJSONString(workResult));
        System.out.println("A - Thread:" + Thread.currentThread().getName() + "- end --" + SystemClock.now());
    }

    @Override
    public Integer action(Integer integer, Map<String, WorkerWrapper> map) {
        Integer res = integer + 1;
        return res;
    }

    @Override
    public Integer defaultValue() {
        return IWorker.super.defaultValue();
    }
}
